﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GAE_PI.Models;
using System.Xml;
using GAE_PI.Exceptions;

namespace GAE_PI.Controllers
{
    public class NouvelleActiviteController : Controller
    {
        //
        // GET: /NouvelleActivite/
        public ActionResult NouvelleActivite()
        {
            if(!DBModel.getDBM().isAdmin())
                return RedirectToAction("ConsulterActivites", "ConsulterActivites");
            try
            {
                if (!DBModel.getDBM().getCatalogueState().Equals("draft"))
                {
                    throw new GAEException("Vous ne pouvez plus ajouter d'activité");
                }
            }
            catch (GAEException ex)
            {
                ex.errorModel.ControllerName = "NouvelleActivite";
                ex.errorModel.ControllerAction = "NouvelleActivite";
                return View("Error", ex.errorModel);
            }
            return View();
        }

        [HttpPost]
        public ActionResult NouvelleActivite(DetailActivityModel d)
        {
            try
            {
                DBModel.getDBM().nouvelleActivite(d);
            }
            catch (GAEException ex)
            {
                ex.errorModel.ControllerName = "NouvelleActivite";
                ex.errorModel.ControllerAction = "NouvelleActivite";
                return View("Error", ex.errorModel);
            }
            return RedirectToAction("DetailActivite", "DetailActivite", new { nomA = d.Nom});
        }
    }
}
